package com.googlecode.animator.controller
{
	import com.googlecode.animator.controller.mediators.SWFLoaderMediator;
	import com.googlecode.animator.data.materials.MaterialVO;
	import com.googlecode.animator.data.materials.MovieMaterialVO;
	import com.googlecode.animator.data.objects3d.CubeVO;
	import com.googlecode.animator.data.objects3d.Object3DVO;
	import com.googlecode.animator.data.objects3d.PlaneVO;
	import com.googlecode.animator.data.objects3d.SphereVO;
	
	import flash.utils.Dictionary;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	
	
	/**
	 * Handles a change to an Object3D's material. 
	 * @author USER
	 * 
	 */
	public class PropertiesUpdateMaterialCommand extends BaseCommand
	{
		private var _object3D:Object3DVO;
		
		/**
		 * Executes command. 
		 * @param notification
		 * 
		 */
		override public function execute(notification:INotification):void
		{
			super.execute(notification);
			
			var mat:MaterialVO;
			
			_object3D = notification.getBody() as Object3DVO;

			
			
			if(_object3D is PlaneVO)
			{
				mat = (_object3D as PlaneVO).material;
			}

			if(_object3D is CubeVO)
			{
				var mList:Dictionary = (_object3D as CubeVO).materialsList;
				mat = mList[(_object3D as CubeVO).selectedFace];
			}
			
			if(_object3D is SphereVO)
			{
				mat = (_object3D as SphereVO).material;
			}

			if(mat is MovieMaterialVO)
			{
				
				var mediator:IMediator = new SWFLoaderMediator(_object3D);
				facade.registerMediator(mediator);
				
				return;
			}
			
			settings.setObject3DMaterial(_object3D); 	
		}
		
	}
}